{% extends 'AdminBundle::layout.html.twig' %}

{% block title %}编辑个人信息{% endblock %}

{% block css %}
    <style>
        .com-list-box{
            width: 725px;
        }
    </style>
{% endblock %}

{% block top %}
    {#{{ dump() }}#}
    {{ parent() }}
{% endblock %}



    {% block left_body_top %}
        {{ parent() }}
    {% endblock %}

    {% block left_body %}
        {{ parent() }}
    {% endblock %}

    {% block right_body %}
    <div class="page-header">
        <div class="page-right-top">
            <div class="right-top">
                <span class="right-title">系统设置</span>
            </div>
            <div class="top-nav top-nav-active">修改密码</div>
        </div>
        <div class="main-content">
            <div class="mes-content">

                <div class="main-mes-content">
                    <form id="comMesBtn">
                        <div class="com-list">
                            <div class="com-list-box">
                                <div class="com-left fl">旧密码</div>
                                <input type="password" name="password" class="is-change pop-com-input" placeholder="请输入旧密码">
                            </div>

                            <div class="com-list-box">
                                <div class="com-left fl">新密码</div>
                                <input type="password" name="new_password" maxlength="18" class="pop-com-key" placeholder="请输入新密码">
                                <span class="pop-com-num" style="width: 140px;">6~18位字母或数字</span>
                            </div>

                            <div class="com-list-box">
                                <div class="com-left fl">确认密码</div>
                                <input type="password" name="comfirm_password" maxlength="18" class="pop-com-key" placeholder="请再次输入密码">
                                <span class="pop-com-num" style="width: 140px;">6~18位字母或数字</span>
                            </div>

                            <div class="clearfix"></div>
                            <div class="add-mem-box" style="margin-top: 40px;">
                                <div class="com-left fl"></div>
                                <div class="acc-opera-btn fl mem-btn p-first-btn">保存</div>
                                <a class="acc-opera-btn fl mem-cancel" href="">取消</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    {% endblock %}

{% block box %}
{% endblock %}


{% block javascript %}
<script type="text/javascript">
    $(function () {

        SidebarHighlighting('8');

        SonSidebar('8', '2');

        // 点击保存
        $('.p-first-btn').on('click', function() {
            var param = $('#comMesBtn').serializeObject();

            if ($.trim(param.password) == '' || $.trim(param.new_password) == '' || $.trim(param.comfirm_password) == '') {
                popStatus(2, '请填写完整', 1, '', true);
                return;
            }

            if ($.trim(param.password).length < 6 || $.trim(param.password).length > 18) {
                popStatus(2, '旧密码长度不合法', 1, '', true);
                return;
            }

            if ($.trim(param.new_password).length < 6 || $.trim(param.new_password).length > 18) {
                popStatus(2, '新密码长度不合法', 1, '', true);
                return;
            }

            if ($.trim(param.comfirm_password).length < 6 || $.trim(param.comfirm_password).length > 18) {
                popStatus(2, '确认密码长度不合法', 1, '', true);
                return;
            }

            if ($.trim(param.new_password) != $.trim(param.comfirm_password)) {
                popStatus(2, '新密码与确认密码不一样', 1, '', true);
                return;
            }

            console.log(param);

            $.post("{{ path('api_admin_auth_update_password') }}",param,function (data) {
                console.log(data);
                if(data.errorCode == 0){
                    popStatus(1, data.message, 1, '', true);
                    location.href = "{{ path('auth_login') }}";
                } else {
                    popStatus(2, data.message, 1, '', true);
                }
            })
        });

    })
</script>
{% endblock %}